<?php
namespace Admin\Controller;

/**
 * 行为控制器
 * @author huajie <banhuajie@163.com>
 */
class SchoolController extends AdminController {
	//
	public function relationXi(){
		$schoolList = D('School')->select();
		$this->assign('schoolList', $schoolList);
		$xiList = D('Xi')->select();
		$this->assign('xiList', $xiList);
		$relationList = D('SchoolXi')->select();
		$this->assign('relationList', $relationList);
		$this->display();
	}
	
	Public function doRelation(){
		if (IS_POST) {
			$dataList = array();
			foreach ($_POST as $schoolId => $xiIdList){
				foreach ($xiIdList as $xiId){
					$item = array(
						'school_id' => $schoolId,
						'xi_id' => $xiId
					);
					$dataList[] = $item;
				}
			}
			$r1 = D('SchoolXi')->where('1')->delete();
			if ($r1 !== false) {
				$result = D('SchoolXi')->addAll($dataList);
				if ($result !== false) {
					$this->success('操作成功', '');;
				}
			}
		}
	}
}